<template>
  <div>
    <el-card class="box-card">
      <div>
        <div>
          <el-input placeholder="请输入教师名称" v-model="parms.teacherName" size="mini" clearable style="width: 250px;margin-right:20px" />
          <el-input placeholder="请输入手机号" v-model="parms.phone" size="mini" clearable style="width: 250px;margin-right:20px" />
          <el-button size="mini" type="primary" @click="serch()" icon="el-icon-search">搜索</el-button>
          <el-button size="mini" type="primary" @click="add()" icon="el-icon-plus">新增</el-button>
        </div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px">
      <el-table :data="tableData" border="" style="width: 100%" @selection-change="handleSelectionChange" v-loading="loading">
        <el-table-column type="index" label="序号" width="50" align="center" />
        <el-table-column label="操作" align="center" width="150">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="editor(scope.row.id)">修改</el-button>
            <el-button size="mini" type="text" @click="del(scope.row.id)" style="color: red">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="teacherName" label="教师名字" align="center" />
        <el-table-column prop="schoolName" label="所属学校" align="center" />
        <el-table-column prop="phonenumber" label="电话号码" align="center" />
        <el-table-column label="状态" align="center" width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.deleteFlag == 0">正常</span>
            <span v-if="scope.row.deleteFlag == 1">未认证</span>
            <span v-if="scope.row.deleteFlag == 2">禁用</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="parms.pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="parms.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
        style="margin-top: 20px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </el-card>
    <el-dialog title="新增" :visible.sync="dialogVisible" width="40%" style="margin-top: 100px">
      <Add @handCancle="handCancle"></Add>
    </el-dialog>
    <el-dialog title="详情" :visible.sync="dialogVisible2" width="40%" style="margin-top: 100px">
      <Editor @handCancle="handCancle" :id="id" :showDialog="dialogVisible2"></Editor>
    </el-dialog> 
  </div>
</template>

<script>
import { getList } from '@/api/teacher/teacher'
import Add from './add.vue'
import Editor from './editor.vue'
export default {
  components: {
    Add,
    Editor
  },
  data() {
    return {
      input: '',
      options: '',
      tableData: [1, 2],
      switch1: true,
      dialogVisible: false,
      dialogVisible2: false,
      value: 10,
      parms:{
        pageNum: 1,
        pageSize: 5,
        teacherName: '',
        phone: ''
      },
      id: null,
      total: null,
      loading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    editor(id) {
      this.id = id
    },
    serch() {
      this.getList()
    },
    add() {
      this.dialogVisible = true
    },
    getList() {
      this.loading = true
      getList(this.parms.pageNum,this.parms.pageSize,this.parms.teacherName,this.parms.phone).then(res => {
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    editor(id) {
      this.id = id
      this.dialogVisible2 = true
    },
    release() {
      this.dialogVisible1 = true
    },
    handCancle(e) {
      this.dialogVisible = false
      this.dialogVisible2 = false
      if(e == 1){
        this.getList()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.parms.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.parms.pageNum = val
      this.getList()
    }
  }
}
</script>

<style>
.flex{
  display: flex;
  justify-content: space-between;
}
.el-table th.gutter {
  display: table-cell !important
}
</style>
